package com.db.report;

import com.db.protocol.message.ReportMessage;

import java.util.LinkedList;
import java.util.List;

/**
 * @author nulls.narik
 */
public class Storage {

    private final List<ReportMessage> list;
    private final Object monitor = new Object();

    public Storage() {
        list = new LinkedList<ReportMessage>();
    }

    public void add(ReportMessage message) {
        synchronized (monitor) {
            list.add(message);
        }
    }

    public List<ReportMessage> getAll() {
        synchronized (monitor) {
            List<ReportMessage> copyList = new LinkedList<ReportMessage>(list);
            list.clear();
            return copyList;
        }
    }
}
